﻿Imports Cls_Common
Imports VSModel
Partial Class Control_TiepNhan_UpdateParent
    Inherits System.Web.UI.UserControl

    Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        Using _data As New VSEntities
            Dim p = (From q In _data.CertifiedHouseholds Where q.CertifiedID = txtId.Text Select q).FirstOrDefault
            If Not p Is Nothing Then
                Dim _ParentId As Integer = GetParentId(txtId.Text)
                p.ParentId = _ParentId
                _data.SaveChanges()
            End If
        End Using

    End Sub
    Function GetParentId(ByVal _CertifiedId As Integer) As Integer

        Using _data As New VSEntities
            Dim _p = (From q In _data.CertifiedHouseholds Where q.CertifiedID = _CertifiedId Select q).FirstOrDefault
            If Not _p Is Nothing AndAlso _p.ParentId <> _p.CertifiedID Then
                Return GetParentId(_p.ParentId)
            End If

        End Using
        Return _CertifiedId
    End Function
End Class
